package app.objectstoragedemo.config;

import app.objectstoragedemo.Pojo.FinalClass.AppConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
@Slf4j
public class WebConfig implements WebMvcConfigurer {

    private final AppConfig appConfig;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        if (!appConfig.isEnableHtml()) {
            log.info("禁用首页");
            // 禁用首页
            registry.addViewController("/").setViewName("forward:/404"); // 指向404页面
            return;
        }
        log.info("启用 index.html 的映射,可以访问:{}", appConfig.getLocalhostPort());
    }

}
